package com.ogilvy.cms.dao.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.ogilvy.cms.bean.CmsTemplateField;
import com.ogilvy.cms.dao.CmsTemplateFieldDao;
import com.ogilvy.frame.hibernate.BaseDaoImpl;
@Repository
public class CmsTemplateFieldDaoImpl extends BaseDaoImpl<CmsTemplateField> implements CmsTemplateFieldDao{

	public List<CmsTemplateField> getListByScreen(Map<String, String> screenMap) {
		StringBuffer hql=new StringBuffer();
		hql.append("from com.ogilvy.cms.bean.CmsTemplateField ctf where ");
		 hql.append("ctf.ctfCmtId like '%"+screenMap.get("ctfCmtId")+"%'");
		// 建立查询语句
		Query query = getSession().createQuery(hql.toString());
		List<CmsTemplateField>  list = query.list();
		if (list == null) {
			list = new ArrayList<CmsTemplateField>();
		}
		return list;
	}

	public Boolean isHaveName(String ctfName) {
		StringBuffer hql=new StringBuffer();
		hql.append("from com.ogilvy.cms.bean.CmsTemplateField ctf where ");
		hql.append(" ctf.ctfName = '"+ctfName+"'");
		Query query = getSession().createQuery(hql.toString());
		List<CmsTemplateField>  list = query.list();
		if (list == null || list.size()==0) {
			return false;
		}else
		{
			return true;
		}
	}

	public List<CmsTemplateField> selectTemplateFieldByCmtId(int cmtId) {
		StringBuffer hql=new StringBuffer();
		hql.append("from com.ogilvy.cms.bean.CmsTemplateField ctf where ");
		 hql.append("ctf.ctfCmtId='"+cmtId+"'");
		// 建立查询语句
		Query query = getSession().createQuery(hql.toString());
		List<CmsTemplateField>  list = query.list();
		if (list == null) {
			list = new ArrayList<CmsTemplateField>();
		}
		return list;
	}

}
